package com.njupt.towersutils.components;

import com.njupt.towersutils.domain.ManagerInfos;
import com.njupt.towersutils.mapper.ManagerInfosMapper;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MYSQLTORedis {
    @Resource
    private ManagerInfosMapper managerInfosMapper;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Scheduled(cron = "0 42 19 * * ?")
//    @Scheduled(fixedRate = 1000)
    public void managersDataTranslansfrom(){
//        读取所有的mysql managerinfos数据 发送到redis数据库的manags hash中
        List<ManagerInfos> mis=managerInfosMapper.findAll();
        for (ManagerInfos mi:mis){
            stringRedisTemplate.opsForHash()
                    .put("manages",mi.getLoginname()+mi.getLoginpwd(),
                            mi.toString());
        }


    }
}
